package com.egao.common.module.system.controller;

import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.JsonResult;
import com.egao.common.module.system.entity.Crawler;
import com.egao.common.module.system.service.CrawlerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 爬虫管理
 * @author pyx
 */
@Api(tags = "爬虫管理")
@RestController
@RequestMapping("${api}")
public class CrawlerController {

    @Autowired
    private CrawlerService crawlerService;

    @PreAuthorize("hasAuthority('sys:college:list')")
    @ApiOperation("查询所有数据")
    @GetMapping("/sys/crawler/list")
    public JsonResult list(Integer type){
        return JsonResult.ok().setData(crawlerService.listAll(type));
    }

    @PreAuthorize("hasAuthority('sys:college:insert')")
    @OperLog(value = "爬虫管理", desc = "修改爬虫设置", result = true)
    @ApiOperation("修改爬虫设置")
    @PutMapping("/sys/crawler/update")
    public JsonResult update(@RequestBody List<Crawler> crawlerList){
        return crawlerService.updateList(crawlerList);
    }
}
